package com.grieous.wow.dao.impl;

import java.util.List;
import java.util.Map;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import com.grieous.wow.dao.BatchDao;
import com.grieous.wow.dao.Page;
import com.grieous.wow.dao.GenericDao;
import com.grieous.wow.entity.User;

@Repository("userDao")
public class UserDaoImpl extends SqlSessionDaoSupport implements
		GenericDao<User>, Page, BatchDao {

	@Override
	public int add(User user) {
		return getSqlSession().insert("mybatis.mapper.UserMapper.insertSelective",
				user);

	}

	@Override
	public int update(User user) {
		return getSqlSession().update(
				"mybatis.mapper.UserMapper.updateByPrimaryKeySelective", user);

	}

	@Override
	public int delete(User user) {
		return getSqlSession().delete("mybatis.mapper.UserMapper.delete", user);

	}

	@Override
	public int delete(Map<String, Object> map) {
		return getSqlSession().delete("mybatis.mapper.UserMapper.deleteByMap", map);

	}

	@Override
	public List<User> findListByCondition(Map<String, Object> map) {
		List<User> list = getSqlSession().selectList("mybatis.mapper.UserMapper.getUser", map);
		return list;
	}

	@Override
	public int findCountByCondition(Map<String, Object> map) {
		Object obj = getSqlSession().selectOne(
				"mybatis.mapper.UserMapper.getUserCount", map);
		return (Integer) (obj == null ? 0 : obj);
	}

	@Override
	public int update(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return 0;
	}

}
